// pages/modifythe/modifythe.js
var util = require("../../utils/util.js")
var api = require("../../utils/api.js")
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        mobile: '',//获取手机号码
        userpass: '',//旧密码
        userpass1: '',//新密码
        userpass2: '',//确认密码
        userinfo: '',
    },
    userpassInput: function(e) {
        this.setData({
            userpass: e.detail.value
        })
    },
    userpassInput1: function(e) {
        this.setData({
            userpass1: e.detail.value
        })
    },
    userpassInput2: function(e) {
        this.setData({
            userpass2: e.detail.value
        })
    },
    dologin: function() {
        var that = this
        wx.getStorage({
            key: 'userInfo',
            success: function(res) {
                that.setData({
                    mobile: res.data.mobile
                })
                if (that.data.userpass.length == 0) {
                    api.showError("请输入旧密码")
                    return;
                }
                if (that.data.userpass.length < 6) {
                    api.showError("旧密码的长度不能小于六位数")
                    return;
                }
                if (that.data.userpass1.length == 0) {
                    api.showError("请输入新密码")
                    return;
                }
                if (that.data.userpass1.length < 6) {
                    api.showError("新密码的长度不能小于六位数")
                    return;
                }
                if (that.data.userpass2.length == 0) {
                    api.showError("请输入确认密码")
                    return;
                }
                if (that.data.userpass1 != that.data.userpass2) {
                    api.showError("两次密码不一致")
                    return;
                }
				var data={
					mobile:that.data.mobile,
					oldpass: that.data.userpass,
					newpass:that.data.userpass1,
				}
				var url = app.u.HOME_URL + app.u.RESETPASSWORD
				api.requestUrl(data,url).then(res => {
					if (res.code == 200 || res.code == 1){
                        wx.clearStorage({
							success: function () {
								api.showError('修改成功')
								setTimeout(function(){
									wx.navigateTo({
										url: '../login/login',
									})
								},500)
							},
							fail: function () {
								api.showError("修改失败")
							},
						})
					}else{
						api.showError('修改失败')
					}
				})
            },
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
		wx.showShareMenu({
			withShareTicket: true
		}) 
    },
})